<?php session_start(); ?>
<?php
function __autoload($class_name) {
    include '../class/' . $class_name . '.php';
}
?>
<?php include("functions.php"); ?>
<?php include("connection.php"); ?>
<?php $settings = new Settings(); ?>


<?php
	if (isLoggedIn()) {
		$user = new FantasyUser($_SESSION['bl_user_id']);
	}
	else {
		$user = new FantasyUser();
	}	
	
	/* making transfers and changing captains */
	if (isset($_GET['pos']) && isset($_GET['plr'])) {
		$user->transferPlayer($_GET['pos'], $_GET['plr'], $settings->currentRound);
	}	
	
	$user->getSeasonRoster();	// punimo postave
	$user->getAllStats();		// punimo statistiku
	$user->calculateTotalPoints();
	
	// podaci
	$k = $settings->currentRound;
	
?>


<div class="fts_roster">
<?php
	$poz = array("pg", "sg", "sf", "pf", "c");
	foreach($poz as $p) {
		$captText = "";
?>
	<div class="fts_roster_player fts_<?php echo $p; ?>">
		<img src="media/players/<?php echo $user->postava[$k][$p]->slika; ?>" />
		<?php $coef = 1; if ($user->kapiteni[$k]->id == $user->postava[$k][$p]->id) {$coef = 2; $captText = "(C)";}  ?>
		<div class="fts_roster_player_name"><a href="player/<?php echo $user->postava[$k][$p]->id; ?>/<?php echo $user->postava[$k][$p]->ime.
		"-".$user->postava[$k][$p]->prezime; ?>"><?php echo $user->postava[$k][$p]->prezime . " " . $captText ?></a></div>
		<div class="fts_roster_player_points"><?php echo $coef*$user->postava[$k][$p]->stats[$user->findMatchForRound($k, $user->postava[$k][$p])]->BLindex; ?> pts</div>
	</div>
<?php
	}
?>

<form id="fantasyCaptain">
	<label for="captain">Captain: 
    	<select id="captain" name="capt">
        	<?php
				foreach ($user->postava[$settings->currentRound] as $pl) {
					$sel = "";
					if ($pl->id == $user->kapiteni[$settings->currentRound]->id) $sel = "selected='selected'";
					echo "<option ".$sel." value='".$pl->id."'>".$pl->ime. " ". $pl->prezime."</option>";
				}
			?>
        </select>
    </label>
</form>

</div>
                    <!-- statistika za gameweek -->
                    <table class="tabela teamStatistics" cellpadding="0" cellspacing="0">
                        <thead>
                            <tr>
                            	<td></td>
                            	<td class="statsPlayerName">Player</td>
                            	<td>FT</td>
                            	<td>2PT</td>
                            	<td>3PT</td>
                            	<td>PTS</td>
                            	<td>ASS</td>
                            	<td>DRB</td>
                            	<td>ORB</td>
                            	<td>BLK</td>
                            	<td>FLS</td>
                            	<td>IND</td>
                            </tr>
                        </thead>
                        <tbody>
                        
                        <?php 
							$poz = array("pg", "sg", "sf", "pf", "c");
							foreach($poz as $p) {
								$user->postava[$k][$p]->getStats($k);
								$user->postava[$k][$p]->calculateTotalStats();
								$mecid = $user->findMatchForRound($k, $user->postava[$k][$p]);
						?>
                        
                        	<tr>
                            	<td class="statsOdd"><?php echo strtoupper($p); ?></td>
                            	<td class="statsPlayerName"><a href="player/<?php echo $user->postava[$k][$p]->id; ?>/<?php echo $user->postava[$k][$p]->ime."-".$user->postava[$k][$p]->prezime; ?>"><?php echo $user->postava[$k][$p]->ime; ?> <?php echo $user->postava[$k][$p]->prezime; ?></a></td>
                            	<td class="statsOdd"><?php echo $user->postava[$k][$p]->stats[$mecid]->ft; ?></td>
                            	<td><?php echo $user->postava[$k][$p]->stats[$mecid]->fg; ?></td>
                            	<td class="statsOdd"><?php echo $user->postava[$k][$p]->stats[$mecid]->threept; ?></td>
                            	<td><?php echo $user->postava[$k][$p]->stats[$mecid]->pts; ?></td>
                            	<td class="statsOdd"><?php echo $user->postava[$k][$p]->stats[$mecid]->ast; ?></td>
                            	<td><?php echo $user->postava[$k][$p]->stats[$mecid]->drbd; ?></td>
                            	<td class="statsOdd"><?php echo $user->postava[$k][$p]->stats[$mecid]->orbd; ?></td>
                            	<td><?php echo $user->postava[$k][$p]->stats[$mecid]->blk; ?></td>
                            	<td class="statsOdd"><?php echo $user->postava[$k][$p]->stats[$mecid]->licne; ?></td>
                            	<td><strong><?php echo $user->postava[$k][$p]->stats[$mecid]->BLindex; ?></strong></td>
                            </tr>
                        <?php 
							}							
						?>
                        
                        </tbody>
                        </table>

